package com.example.shiyan3

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.material3.Button
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp

// 定义艺术品数据类
data class Artwork(
    val imageRes: Int,
    val title: String,
    val artist: String,
    val year: Int
)

@Composable
fun ArtSpaceApp() {
    // 模拟数据
    val artworks = listOf(
        Artwork(R.drawable.x, "Still Life of Blue Rose and Other Flowers", "Owen Scott", 2021),
        Artwork(R.drawable.z, "Mountain Landscape", "Jane Doe", 2020),
        Artwork(R.drawable.y, "Abstract Colors", "Alex Kim", 2019)
    )

    var currentIndex by remember { mutableStateOf(0) }

    Surface(
        modifier = Modifier.fillMaxSize()
    ) {
        Column(
            modifier = Modifier
                .fillMaxSize()
                .padding(32.dp),
            horizontalAlignment = Alignment.CenterHorizontally,
            verticalArrangement = Arrangement.Center
        ) {
            // 图片展示区域
            Image(
                painter = painterResource(id = artworks[currentIndex].imageRes),
                contentDescription = artworks[currentIndex].title,
                modifier = Modifier
                    .weight(1f)
                    .padding(bottom = 32.dp)
            )

            // 作品信息区域
            Column(
                modifier = Modifier.fillMaxWidth(),
                horizontalAlignment = Alignment.CenterHorizontally
            ) {
                Text(text = artworks[currentIndex].title)
                Text(text = "${artworks[currentIndex].artist} (${artworks[currentIndex].year})")
            }

            Spacer(modifier = Modifier.height(32.dp))

            // 按钮控制区域
            Row(
                modifier = Modifier.fillMaxWidth(),
                horizontalArrangement = Arrangement.SpaceEvenly
            ) {
                Button(
                    onClick = {
                        currentIndex = (currentIndex - 1 + artworks.size) % artworks.size
                    }
                ) {
                    Text("Previous")
                }

                Button(
                    onClick = {
                        currentIndex = (currentIndex + 1) % artworks.size
                    }
                ) {
                    Text("Next")
                }
            }
        }
    }
}
@Preview(showBackground = true, showSystemUi = true)
@Composable
fun ArtSpaceAppPreview() {
    ArtSpaceApp()
}